home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / MacInternalFrameBorder.java < prev    next >
Text File  |  1998-06-30  |  6KB  |  176 lines

  1. /*
  2.  * @(#)MacInternalFrameBorder.java    1.6 98/02/02
  3.  *
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  *
  19.  */
  20.  
  21.  
  22. package com.sun.java.swing.plaf.mac;
  23.  
  24. import java.awt.Graphics;
  25. import java.awt.Dimension;
  26. import java.awt.Rectangle;
  27. import java.awt.Color;
  28. import java.awt.Insets;
  29.  
  30. import java.awt.*;
  31. import java.beans.*;
  32.  
  33. import com.sun.java.swing.*;
  34. import com.sun.java.swing.border.AbstractBorder;
  35.  
  36. /**
  37.  * <p>
  38.  * Warning: serialized objects of this class will not be compatible with
  39.  * future swing releases.  The current serialization support is appropriate
  40.  * for short term storage or RMI between Swing1.0 applications.  It will
  41.  * not be possible to load serialized Swing1.0 objects with future releases
  42.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  43.  * baseline for the serialized form of Swing objects.
  44.  *
  45.  * @version @(#)MacInternalFrameBorder.java    1.0 11/24/97
  46.  * @author Symantec
  47.  * @author David Bustin
  48.  */
  49.  
  50. public class MacInternalFrameBorder extends MacFrameBorder {
  51.  
  52.     JInternalFrame frame;
  53.  
  54.     // The size of the bounding box for Mac frame corners.
  55.     public final static int CORNER_SIZE = 22;
  56.  
  57.     /** Constructs an InternalFrameBorder for the InternalFrame
  58.       * <b>aFrame</b>.
  59.       */
  60.     public MacInternalFrameBorder(JInternalFrame aFrame) {
  61.         super(aFrame);
  62.         frame = aFrame;
  63.     }
  64.  
  65.     /** Sets the InternalFrameBorder's InternalFrame.
  66.       */
  67.     public void setFrame(JInternalFrame aFrame) {
  68.         frame = aFrame;
  69.     }
  70.  
  71.     /** Returns the InternalFrameBorder's InternalFrame.
  72.       * @see #setFrame
  73.       */
  74.     public JInternalFrame frame() {
  75.         return frame;
  76.     }
  77.  
  78.     /** Returns the width of the InternalFrameBorder's resize controls,
  79.       * appearing along the InternalFrameBorder's bottom border.  Clicking
  80.       * and dragging within these controls lets the user change both the
  81.       * InternalFrame's width and height, while dragging between the controls
  82.       * constrains resizing to just the vertical dimension.  Override this
  83.       * method if you implement your own bottom border painting and use a
  84.       * resize control with a different size.
  85.       */
  86.     public int resizePartWidth() {
  87.         if (!frame.isResizable()) {
  88.             return 0;
  89.         }
  90.         return MacFrameBorder.BORDER_SIZE;
  91.     }
  92.  
  93.     /** Draws the InternalFrameBorder's top border.
  94.      */
  95.     protected boolean drawTopBorder(Component c, Graphics g, 
  96.                                     int x, int y, int width, int height) {
  97.         if (super.drawTopBorder(c, g, x, y, width, height) && 
  98.             frame.isResizable()) {
  99.             return true;
  100.         }
  101.         return false;
  102.     }
  103.  
  104.     /** Draws the InternalFrameBorder's left border.
  105.       */
  106.     protected boolean drawLeftBorder(Component c, Graphics g, int x, int y, 
  107.                                      int width, int height) {
  108.         if (super.drawLeftBorder(c, g, x, y, width, height) && 
  109.             frame.isResizable()) {
  110.  
  111.             if (!isActiveFrame() || height < 2 * CORNER_SIZE)
  112.                 return true;
  113.  
  114.             // draw resize marks
  115.             g.setColor(GS6Color);
  116.             g.drawLine(x + 2, height - CORNER_SIZE, x + 5, height - CORNER_SIZE);
  117.  
  118.             g.setColor(GSWColor);
  119.             g.drawLine(x + 2, height - CORNER_SIZE + 1, x + 5, height - CORNER_SIZE + 1);
  120.             return true;
  121.         }
  122.         return false;
  123.     }
  124.  
  125.     /** Draws the InternalFrameBorder's right border.
  126.       */
  127.     protected boolean drawRightBorder(Component c, Graphics g, int x, int y, 
  128.                                       int width, int height) {
  129.         if (super.drawRightBorder(c, g, x, y, width, height) && 
  130.             frame.isResizable()) {
  131.  
  132.             if (!isActiveFrame() || height < 2 * CORNER_SIZE)
  133.                 return true;
  134.  
  135.             // draw resize marks
  136.             g.setColor(GS6Color);
  137.             g.drawLine(width - 6, height - CORNER_SIZE + 1, width - 3, height - CORNER_SIZE + 1);
  138.  
  139.             g.setColor(GSWColor);
  140.             g.drawLine(width - 6, height - CORNER_SIZE, width - 3, height - CORNER_SIZE);
  141.             return true;
  142.         }
  143.         return false;
  144.     }
  145.  
  146.     /** Draws the InternalFrameBorder's bottom border.
  147.       */
  148.     protected boolean drawBottomBorder(Component c, Graphics g, int x, int y, 
  149.                                        int width, int height) {
  150.  
  151.         if (super.drawBottomBorder(c, g, x, y, width, height) &&
  152.             frame.isResizable()) {
  153.  
  154.             if (!isActiveFrame() || height < 2 * CORNER_SIZE)
  155.                 return true;
  156.  
  157.             // draw resize marks
  158.             g.setColor(GS6Color);
  159.             g.drawLine(x + CORNER_SIZE - 1, height - 6, x + CORNER_SIZE - 1, height - 3);
  160.             g.drawLine(width - CORNER_SIZE, height - 6, width - CORNER_SIZE, height - 3);
  161.  
  162.             g.setColor(GSWColor);
  163.             g.drawLine(x + CORNER_SIZE, height - 6, x + CORNER_SIZE, height - 3);
  164.             g.drawLine(width - CORNER_SIZE + 1, height - 6, width - CORNER_SIZE + 1, height - 3);
  165.  
  166.             return true;
  167.         }
  168.         return false;
  169.     }
  170.  
  171.     // Returns true if the associated internal frame has focus.
  172.     protected boolean isActiveFrame() {
  173.         return frame.isSelected();
  174.     }
  175. }
  176.